import app
import requests


class OrderApi:
    def __init__(self):
        self.creat_url = app.host_url + "order"
        self.check_url = app.host_url + "order/{}"
        self.get_url = app.host_url + "order/by_user"

    def creatApi(self, product_id=8, count=1):
        return requests.post(url=self.creat_url, headers=app.header,
                             json={"products": [{"product_id": product_id, "count": count}]})

    def checkApi(self, id=50):
        data = {"token": app.header.get("token")}
        return requests.get(url=self.check_url.format(id), headers=data)

    def getApi(self, page=1):
        data = {"token": app.header.get("token")}
        page_id = {"page": page}
        return requests.get(url=self.get_url, headers=data, params=page_id)
